package com.liliudong.makabaka.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liliudong.makabaka.sys.entity.SysMenu;
import com.liliudong.makabaka.sys.mapper.SysMenuMapper;
import com.liliudong.makabaka.sys.service.SysMenuService;
import com.liliudong.makabaka.util.TreeUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author liudo
 * @description 针对表【sys_menu(菜单权限表)】的数据库操作Service实现
 * @createDate 2023-09-23 16:38:57
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu>
        implements SysMenuService {

    @Override
    public List<SysMenu> getTree() {
        List<SysMenu> sysMenus = baseMapper.selectList(null);
        List<SysMenu> topLevelMenus = sysMenus.stream().filter(sysMenu -> 0 == sysMenu.getParentId())
                .collect(Collectors.toList());
        TreeUtil.getChildrenMenus(topLevelMenus, sysMenus);
        return topLevelMenus;
    }
}




